---
description: "Reference for Nitric's v0 Go library - Store a new secret value"
---

# Go - Secret.Put()

Store a new secret value, creating a new [version](./secret-version) to store the value.

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  versionRef, err := secret.Put(context.TODO(), []byte("content"))
  if err != nil {
    return
  }

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="ctx" required type="context">
    The context of the call, used for tracing.
  </Property>
  <Property name="secret" required type="[]byte">
    The new secret value to store in the secrets manager.
  </Property>
</Properties>

### Notes

A new secret version is always created when calling `Put()`, the versions will automatically be provided a unique id. This behavior is dependent on the underlying secrets manager.

## Examples

### Store a new secret value

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretPutting)
  if err != nil {
    return
  }

  versionRef, err := secret.Put(context.TODO(), []byte("content"))
  if err != nil {
    return
  }

  nitric.Run()
}
```

### Get the id of a new secret version

Calling `put()` returns a promise to a reference to the new secret version. Storing the ID of the new version can be useful if you need to retrieve that specific value again in future using [version.access()](./secret-version-access)

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  versionRef, err := secret.Put(context.TODO(), []byte("content"))
  if err != nil {
    return
  }

  fmt.Println(versionRef.Version())

  nitric.Run()
}
```
